//
//  EXT+UIBarButtonItem.swift
//  BAweibo
//
//  Created by baggio on 2017/8/2.
//  Copyright © 2017年 baggio. All rights reserved.
//

//扩展 UIBarButtonItem 的构造函数

//swift文件默认import Foundation，改成 UIKit
//import Foundation
import UIKit

extension UIBarButtonItem{
    
    //通过 便利构造函数 扩展 UIBarButtonItem 的构造函数
    //UIBarButtonItem(customView: UIView)
    //注意，不是 convenience public override init()
    convenience init(title:String?,
                     imgName:String?,
                     target: Any?,
                     action: Selector?){
        
//        let btn=UIButton()
//        
//        if let t=title{
//            btn.setTitle(t, for: .normal)
//            btn.setTitleColor(UIColor.darkGray, for: .normal)
//            btn.setTitleColor(BA_COLOR_APP_THEME, for: .highlighted)
//            btn.titleLabel?.font=UIFont.systemFont(ofSize: 14)
//        }
//        if let i=imgName{
//            btn.setImage(UIImage(named:i), for: .normal)
//            btn.setImage(UIImage(named:"\(i)_highlighted"), for: .highlighted)
//        }
//        if let t=target,let a=action{
//            btn.addTarget(t, action: a, for: .touchUpInside)
//        }
//        
//        btn.sizeToFit() //没有这句话，btn不显示
        
        //改用扩展后的 UIButtion 的便利构造函数
        let btn=UIButton(title: title, titleColor: UIColor.darkGray, titleColorHighlight: BA_COLOR_APP_THEME, titleLabelFont: 14, imgName: imgName, backgroundImgName: nil, target: target, action: action)
        
        self.init(customView: btn)
    }



}

